<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Title</title>
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css"
          integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
    <script src="https://cdn.bootcss.com/popper.js/1.12.9/umd/popper.min.js"
            integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
            crossorigin="anonymous"></script>
    <script src="https://cdn.bootcss.com/bootstrap/4.0.0/js/bootstrap.min.js"
            integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
            crossorigin="anonymous"></script>
</head>
<body>
<div class="container-fluid">
    <div class="row  align-items-center">
        <div class="col-sm  text-right" id="agResult">
        </div>
    </div>

</div>
</body>
<script>
    String.prototype.replaceAll = function (s1, s2) {
        return this.replace(new RegExp(s1, "gm"), s2);
    };

    function everySix(arr) {
        var sixArr = [];
        for (var i = 0; i < arr.length; i++) {
            var str = "";
            for (var j = 0; j < 7 && i + j < arr.length; j++) {
                var index = i + j;
                str += arr[index];
            }
            sixArr.push(str);
        }
        return sixArr.slice(0);
    }

    //
    function chuanTongLu(arr, size) {
        var ni = [];
        for (var i = arr.length - 1; i > 0 && i - size >= 0; i--) {
            ni.push(arr[i]);
        }
        var zheng = [];
        for (var x = ni.length - 1; x > 0; x--) {
            zheng.push(ni[x]);
        }
        for (var i = 0; i < arr.length; i++) {
            var suit = true;
            for (var j = 0; j < zheng.length - size; j++) {
                if (arr[i + j] != zheng[j]) {
                    suit = false;
                    break;
                }
                suit = true;
            }
            if (suit) {

            }
        }
    }

    function toArr(result, key) {
        var data = result[key];//[]
        var title = "C00" + key;
        switch (key) {
            case "0" :
                title = "C001";
                break;
            case "1" :
                title = "C002";
                break;
            case "2" :
                title = "C003";
                break;
            case "3" :
                title = "C005";
                break;
            case "4" :
                title = "C006";
                break;

        }
        data = data.substring(1, data.length - 1).replaceAll("\"", "");
        var arr = data.split(',');
        return arr.slice(0);
    }

    /*
    * 从服务器获取数据
    * */
    function getAgData() {
        var r = Math.random();
        $.ajax({
            // url: 'http://www.buziman.com:8080/test/get?r=' + r,
            url: 'http://localhost:8080/test/get?r=' + r,
            type: 'GET',
            dataType: 'TEXT',//'json',TEXT
            success: function (json) {
                $('#agResult').html("");
                var result = eval("(" + json + ")");
                for (var key in result) {
                    var arr = toArr(result, key);
                    var arrStr = arr.join("->");
                    $('#agResult').html($('#agResult').html() + arrStr + ":" + key + "<br/>");//.substring(arrStr.length-17)
                }
            },
            error: function () {
                $('<span>').text(' 服务不可用').insertAfter('#username');
            }
        });
    }

    setInterval(getAgData, 1000);
</script>
</html>